package cn.lili.modules.kit;

import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.payment.entity.dos.*;
import cn.lili.modules.payment.entity.dto.PaymentWakeupParam;
import cn.lili.modules.payment.entity.dto.ProfitSharingRequestDTO;
import cn.lili.modules.payment.entity.dto.SubsidiesParams;
import cn.lili.modules.payment.entity.dto.UrbanSubstationCommissionParams;
import cn.lili.modules.payment.entity.enums.PaymentMethodEnum;
import cn.lili.modules.payment.entity.vo.ApplePaymentVO;
import cn.lili.modules.payment.entity.vo.OutOrderLogVO;
import org.springframework.transaction.annotation.Transactional;

/**
 * 支付接口
 *
 * @author Chopper
 * @since 2020-12-21 09:32
 */
public interface Payment {

    /**
     * 普通移动网页调用支付app
     *
     * @param paymentWakeupParam api参数
     * @return 移动支付所需参数
     */
    default ResultMessage<Object> h5pay(PaymentWakeupParam paymentWakeupParam) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 公众号内部调用支付
     *
     * @param paymentWakeupParam api参数
     * @return 公众号内部支付参数
     */
    default ResultMessage<Object> jsApiPay(PaymentWakeupParam paymentWakeupParam) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * app支付
     *
     * @param paymentWakeupParam 支付参数
     * @return app支付所需参数
     */
    default ResultMessage<Object> appPay(PaymentWakeupParam paymentWakeupParam) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 展示二维码扫描支付
     *
     * @param paymentWakeupParam 支付参数
     * @return 二维码内容
     */
    default ResultMessage<Object> nativePay(PaymentWakeupParam paymentWakeupParam) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 小程序支付
     *
     * @param payParam 支付参数
     * @return 二维码内容
     */
    default ResultMessage<Object> mpPay(PaymentWakeupParam payParam) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 补差方法
     *
     * @param subsidiesParams 补差参数
     */
    default PaymentSubsidies subsidies(SubsidiesParams subsidiesParams) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 查询支付结果 将结果写入传入的对象
     *
     * @param paymentLog 支付日志
     */
    default void checkPaymentResult(PaymentLog paymentLog) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 查询支付结果 将结果写入传入的对象
     *
     * @param combinePaymentLog 合单支付日志
     */
    default void checkPaymentResult(CombinePaymentLog combinePaymentLog) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 退款
     *
     * @param refundLog 退款请求参数
     */
    default void refund(RefundLog refundLog) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 回调
     */
    default void callBack() throws Exception {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 异步通知
     */
    default void paymentNotify() throws Exception {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * Apply异步通知
     */
    default void paymentNotify(ApplePaymentVO applePaymentVO) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 退款异步通知
     */
    default void refundNotify() {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 将账分给平台
     * 必须实现。所以没有默认方法
     *
     * @param paymentLog 支付日志
     */
    OutOrderLog profitSharingPlatform(PaymentLog paymentLog);


    /**
     * 分账接口实现
     */
    default OutOrderLogVO profitSharing(ProfitSharingRequestDTO profitSharingRequestDTO) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 将补差信息分账给平台
     *
     * @param outOrderLog 分账订单
     */
    default void profitSharingSubsidies(OutOrderLog outOrderLog) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 特殊分账接口实现
     *
     * @param outOrderLog             分账订单
     * @param profitSharingRequestDTO 分账参数
     * @return 分账结果
     */
    default OutOrderLogVO specialProfitSharing(OutOrderLog outOrderLog, ProfitSharingRequestDTO profitSharingRequestDTO) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }

    /**
     * 提现
     *
     * @return
     */
    default boolean transfer(UserWithdrawApply userWithdrawApply) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }


    /**
     * 支付异步通知地址
     *
     * @param api               api地址
     * @param paymentMethodEnum 支付类型
     * @return 异步通知地址
     */
    default String notifyUrl(String api, PaymentMethodEnum paymentMethodEnum) {
        return api + "/payment/cashier/notify/" + paymentMethodEnum.name();
    }

    /**
     * 微信付异步通知地址
     *
     * @param api               api地址
     * @param paymentMethodEnum 支付类型
     * @return 异步通知地址
     */
    default String notifyWechat(String api, PaymentMethodEnum paymentMethodEnum) {
        return api + "/payment/cashier/notifyWechat/" + paymentMethodEnum.name();
    }

    /**
     * 支付同步通知地址
     *
     * @param api               api地址
     * @return 异步通知地址
     */
    default String syncUrl(String api) {
        //return api + "/pages/order/myOrder";
        return api + "/pages/cart/payment/payOrder";
    }

    default String syncVipUrl (String api) {
        return api + "/pages/mine/plus/plus";
    }

    /**
     * 退款支付异步通知地址
     *
     * @param api               api地址
     * @param paymentMethodEnum 支付类型
     * @return 异步通知地址
     */
    default String refundNotifyUrl(String api, PaymentMethodEnum paymentMethodEnum) {
        return api + "/payment/refund/notify/" + paymentMethodEnum.name();
    }

    default PaymentUrbanSubstationCommission urbanSubstationCommission(UrbanSubstationCommissionParams urbanSubstationCommissionParams) {
        throw new ServiceException(ResultCode.PAY_ERROR);
    }
}
